import { createStore } from '../vuex/index'

const store = {
  state: {
    userInfo: {},
    associationActivity: [],
  },
  getters: {
    numberOfAwardsReceived(state) {
      return state.associationActivity.length
    },
  },
  mutations: {
    setUserInfo(state, info) {
      state.userInfo = info
    },
    setAssociationActivity(state, data) {
      state.associationActivity = data
    },
  },
  actions: {
    async getUserInfo({ commit }, id) {
      const res = await Promise.resolve({
        id,
        name: '张三',
        age: 20,
        school: 'vue大学',
        sex: '男',
      })
      commit('setUserInfo', res)
    },
    async getAward({ commit }, id) {
      const res = await Promise.resolve([
        {
          userId: id,
          award: '三好学生',
          date: '20200906',
        },
        {
          userId: id,
          award: '学风建设标兵',
          date: '20210908',
        },
        {
          userId: id,
          award: '一等奖学金',
          date: '20210910',
        },
      ])
      commit('setAssociationActivity', res)
    },
  },
}

export default createStore(store);
